import 'package:example/page_follow_up_detail.dart';
import 'package:example/widget_demo/page_widget_list.dart';

import 'page_dkform_init_demo.dart';
import 'page_dkform_transform_demo.dart';
import 'page_dkform_validate_demo.dart';
import 'page_dkform_value_demo.dart';
import 'page_widgets_demo.dart';
import 'package:flutter/material.dart';
import 'page_dkform_simple_demo.dart';
import 'page_dkform_demo.dart';
import 'page_flutter_form_demo.dart';
import 'page_dynamic_dkform.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'page_time_axis_demo.dart';
import 'package:oktoast/oktoast.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return OKToast(
      child:MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        routes: routers,
        home: MyHomePage(title: 'Flutter Demo Home Page1'),
        localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
        ],
        supportedLocales: [
          const Locale('zh', 'CH'),
        ],
      )
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    var routerLists = routers.keys.toList();
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: new Container(
        child: new ListView.builder(
          itemCount: routers.length,
          itemBuilder: (context, index) {
            return new InkWell(
              onTap: () {
                Navigator.of(context).pushNamed(routerLists[index]);
              },
              child: new Card(
                child: new Container(
                  alignment: Alignment.centerLeft,
                  margin: EdgeInsets.symmetric(horizontal: 10),
                  height: 50,
                  child: new Text(routerName[index]),
                ),
              ),
            );
          },
        ),
      ),
    );
  }
}

Map<String, WidgetBuilder> routers = {
  DkWidgetDemo.routeName:(context){
    return DkWidgetDemo();
  },
  WidgetsDemoPage.routeName: (context) {
    return WidgetsDemoPage();
  },
  FlutterFormDemoPage.routeName: (context) {
    return FlutterFormDemoPage();
  },
  DkSimpleFormDemoPage.routeName: (context) {
    return DkSimpleFormDemoPage();
  },
  DkValidateFormDemoPage.routeName: (context) {
    return DkValidateFormDemoPage();
  },
  DkValueFormDemoPage.routeName: (context) {
    return DkValueFormDemoPage();
  },
  DkTransformFormDemoPage.routeName: (context) {
    return DkTransformFormDemoPage();
  },
  DkInitFormDemoPage.routeName: (context) {
    return DkInitFormDemoPage();
  },
  DkFormDemoPage.routeName: (context) {
    return DkFormDemoPage();
  },
  DkDynamicFormDemoPage.routeName: (context) {
    return DkDynamicFormDemoPage();
  },
  FollowUpDetailPage.routeName: (context) {
    return FollowUpDetailPage();
  },
};

var routerName = [
  DkWidgetDemo.name,
  WidgetsDemoPage.name,
  FlutterFormDemoPage.name,
  DkSimpleFormDemoPage.name,
  DkValidateFormDemoPage.name,
  DkValueFormDemoPage.name,
  DkTransformFormDemoPage.name,
  DkInitFormDemoPage.name,
  DkFormDemoPage.name,
  DkDynamicFormDemoPage.name,
  FollowUpDetailPage.name,
];
